Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_launch_template: Fix various bugs #4321

Merged
merged 5 commits into from
Apr 24, 2018
Merged

r/aws_launch_template: Fix various bugs #4321

merged 5 commits into from
Apr 24, 2018

Conversation

stefansundin
Copy link
Contributor

@stefansundin stefansundin commented Apr 23, 2018

These three commits fixes the following errors:

  • Error: aws_launch_template.default: "name_prefix" can only alphanumeric characters and ()./_ symbols

    • aws_launch_template.default: InvalidSnapshotID.Malformed: The snapshot ID '' is not valid. The expected format is snap-xxxxxxxx or snap-xxxxxxxxxxxxxxxxx.
      status code: 400, request id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    • aws_launch_template.default: block_device_mappings.0.ebs: '': source data must be an array or slice, got map

I am not sure if there are more things to fix for the middle one.. The problem is that empty strings were used when the properties were not defined (such as snapshot_id). I tried to find other places in the code that had similar conventions, and I just used the first one that worked for me.

I still haven't learned how to run the tests, so if anyone thinks there needs to be tests added, then please feel free to add them to this PR (edits from maintainers are allowed).

@ghost ghost added the size/S Managed by automation to categorize the size of a PR. label Apr 23, 2018
@ghost ghost added size/M Managed by automation to categorize the size of a PR. and removed size/S Managed by automation to categorize the size of a PR. labels Apr 23, 2018
@stefansundin
Copy link
Contributor Author

I updated the docs to provide some help on the things I had trouble with.. there's an unconventional comment in there that I am not sure how to write in the best way. Please let me know what you think.

@radeksimko radeksimko added bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. labels Apr 24, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @stefansundin -- I would like to get this in before we release v1.16.0 tomorrow so I'll address the feedback in a commit after yours.

Running the acceptance testing is documented at the bottom of the repository README: https://github.com/terraform-providers/terraform-provider-aws/#developing-the-provider

To run the acceptance tests for just this resource, its:

make testacc TEST=./aws TESTARGS='-run=TestAccAWSLaunchTemplate'

@@ -1751,8 +1751,8 @@ func validateLaunchTemplateName(v interface{}, k string) (ws []string, errors []
errors = append(errors, fmt.Errorf("%q cannot be longer than 99 characters, name is limited to 125", k))
} else if !strings.HasSuffix(k, "prefix") && len(value) > 125 {
errors = append(errors, fmt.Errorf("%q cannot be longer than 125 characters", k))
} else if !regexp.MustCompile(`^[0-9a-zA-Z()./_]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf("%q can only alphanumeric characters and ()./_ symbols", k))
} else if !regexp.MustCompile(`^[0-9a-zA-Z()./_\-]+$`).MatchString(value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a dash here looks good according to the EC2 API documentation: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateLaunchTemplate.html

LaunchTemplateName
A name for the launch template.

Type: String

Length Constraints: Minimum length of 3. Maximum length of 128.

Pattern: [a-zA-Z0-9\(\)\.-/_]+

Required: Yes

## Example Usage

```hcl
resource "aws_launch_template" "foo" {
name = "foo"

block_device_mappings {
device_name = "test"
# to change the type or size of the root volume, override the ami's root device name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add this helper information to the block_device_mappings documentation below. I'll adjust on merge 👍 More importantly its better to get the updated device_name information in the example.

@@ -10,16 +10,24 @@ description: |-

Provides an EC2 launch template resource. Can be used to create instances or auto scaling groups.

-> **Note:** All arguments are optional except for either `name`, or `name_prefix`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why this was removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in the commit message, terraform will generate a name if the name is missing. This is also noted in the description of the attribute:

The name of the launch template. If you leave this blank, Terraform will auto-generate a unique name.

@@ -597,7 +597,7 @@ func getBlockDeviceMappings(m []*ec2.LaunchTemplateBlockDeviceMapping) []interfa
ebs["snapshot_id"] = aws.StringValue(v.Ebs.SnapshotId)
}

mapping["ebs"] = ebs
mapping["ebs"] = []interface{}{ebs}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An acceptance test implementing this part of the resource would've caught this. I'll add one.

@bflad bflad added this to the v1.16.0 milestone Apr 24, 2018
@bflad bflad merged commit 8bd25a9 into hashicorp:master Apr 24, 2018
bflad added a commit that referenced this pull request Apr 24, 2018
@bflad
Copy link
Contributor

bflad commented Apr 25, 2018

This has been released in version 1.16.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 6, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. size/M Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants